#pragma once
#include "charset/string.hpp"
#include "charset/textencode.hpp"
#include "event/rwlock.hpp"
using namespace JHCPP::event;
#include <map>

namespace JHCPP
{
	namespace charset
	{	
		class CTextEncodeManager
		{
		public:
			CTextEncodeManager();
			~CTextEncodeManager();

			void add(CTextEncode::Ptr pEncode);
			void add(CTextEncode::Ptr pEncode, const std::string& name);
			void remove(const std::string& name);
			CTextEncode::Ptr find(const std::string& name) const;

		private:
			CTextEncodeManager(const CTextEncodeManager&);
			CTextEncodeManager& operator = (const CTextEncodeManager&);

			struct ILT
			{
				bool operator() (const std::string& s1, const std::string& s2) const
				{
					return JHCPP::charset::icompare(s1, s2) < 0;
				}
			};

			typedef std::map<std::string, CTextEncode::Ptr, ILT> EncodeMap;

			EncodeMap		m_encodeMap;
			mutable CRWLock m_lock;
		};
	}//end of namespace charset
}//end of namespace JHCPP
